﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetfractionHub.Network.Protocol.BASE.Factory
{
    public class FactorySUP : ProtocolMessageFactory
    {
        public enum ParameterEnum : int
        {
            AddFeature = 1,
            RemoveFeature = 2
        }

        // pass list of strings as object to overcome limitations of the keys i.e. can only have one AD and one RM object otherwise
        public override ProtocolMessage Create(ProtocolMessage.MessageTypeEnum messageType, Dictionary<int, object> parameters)
        {
            ProtocolMessage proto = new ProtocolMessage(messageType, ProtocolFeatureBASE.FeatureActions.ActionSUP);

            foreach (ParameterEnum en in parameters.Keys)
            {
                switch (en)
                {
                    case ParameterEnum.AddFeature:
                        foreach (string s in parameters[(int)en] as IEnumerable<string>)
                        {
                            proto.Parameters.Add(new ProtocolParameter("AD", s));
                        }
                        break;
                    case ParameterEnum.RemoveFeature:
                        foreach (string s in parameters[(int)en] as IEnumerable<string>)
                        {
                            proto.Parameters.Add(new ProtocolParameter("RM", s));
                        }
                        break;
                    default:
                        break;
                }
            }
            return proto;
        }
    }
}
